/**
 * 
 */
package com.demo2do.strawberry.entity.startup.fund;

/**
 * Describe the fund status of startups
 * 
 * @author lute
 */
public enum FundStatus {
	
	/** startups which are default in operatiing status */
	DEFAULT("enum.startup-fund-status.default"),
	
	/** startups to display on website as latest startups */
	LATEST("enum.startup-fund-status.latest"),
	
	/** startups to display on website as prefunding startups */
	PREFUNDING("enum.startup-fund-status.prefunding"),
	
	/** startups to display on website as funding startups */
	FUNDING("enum.startup-fund-status.funding"),
	
	/** startups raised funds it expects online */
	FUNDING_SUCCESS("enum.startup-fund-status.funding-success"),
	
	/** startups not raised funds they expects online */
	FUNDING_FAIL("enum.startup-fund-status.funding-fail"),
	
	/** startups raised funds they expect offline*/
	FUNDED("enum.startup-fund-status.funded");
	
	private String key;
	
	/**
	 * 
	 * @param key
	 */
	private FundStatus(String key) {
		this.key = key;
	}
	
	/**
	 * @return the key
	 */
	public String getKey() {
		return this.key;
	}
	
	/**
	 * @return the alias
	 */
	public String getAlias() {
		return this.key.substring(this.key.lastIndexOf(".") + 1);
	}
	
	/**
	 * @return
	 */
	public int getOrdinal() {
		return this.ordinal();
	}
	
	/**
	 * determine whether this FundStatus is configurable by user
	 * 
	 * @return
	 */
	public boolean isConfigurable() {
		return this.ordinal() <= (FundStatus.FUNDING).ordinal();
	}
	
	/**
	 * determin whether this FundStatus is the redis key base
	 * 
	 * @return
	 */
	public boolean isAsRedisKey() {
		return this.isConfigurable() && this.ordinal() > (FundStatus.DEFAULT).ordinal();
	}
	
	/**
	 * 
	 * @param value
	 * @return
	 */
	public static FundStatus aliasOf(String value) {
		for(FundStatus fundStatus : FundStatus.values()) {
			if(fundStatus.getAlias().equalsIgnoreCase(value)) {
				return fundStatus;
			}
		}
		return null;
	}
	
	/**
	 * return fund status accoding to oridnal
	 * 
	 * @param ordinal
	 * @return
	 */
	public static FundStatus aliasOf(int ordinal) {
		for(FundStatus fundStatus : FundStatus.values()) {
			if(fundStatus.ordinal() == ordinal) {
				return fundStatus;
			}
		}
		return null;
	}

}
